﻿function toggleMarkerManager() {
    showMarketManager = !showMarketManager;
    if (mgr) {
        if (showMarketManager) {
            //mgr.addMarkers(markers.countries, 0, 5);
            //mgr.addMarkers(markers.places, 6, 11);
            //mgr.addMarkers(markers.locations, 12);

            if (arrPlace) {
                for (var i = 0; i < arrPlace.length; i++) {
                    //                    var lat = testArray[i]*1;
                    //                    var lng = testArray[i + 1] * 1;
                    //                    var title = testArray[i + 2];
                    //                    addMyPlace(lat, lng,title);
                    //var latlng = new google.maps.LatLng(a[i].lat, a[i].lng);
                    addMyPlace(arrPlace[i].id, arrPlace[i].lat, arrPlace[i].lng, arrPlace[i].title);
                }
            }

            mgr.refresh();
        } else {
            mgr.clearMarkers();
            mgr.refresh();
        }
    } else {
        mgr = new MarkerManager(map, { trackMarkers: true, maxZoom: 15 });
        google.maps.event.addListener(mgr, 'loaded', function () {
            //mgr.addMarkers(markers.countries, 0, 5);
            //mgr.addMarkers(markers.places, 6, 11);
            //mgr.addMarkers(markers.locations, 12);
            if (arrPlace) {
                for (var i = 0; i < arrPlace.length; i++) {
                    addMyPlace(arrPlace[i].id, arrPlace[i].lat, arrPlace[i].lng, arrPlace[i].title);
                }
            }

            mgr.refresh();
        });
    }
}


//Marker manager
google.maps.event.addDomListener(document.getElementById('mgr-cb'), 'click', toggleMarkerManager);

//    if (markers) {
//        for (var level in markers) {
//            for (var i = 0; i < markers[level].length; i++) {
//                var details = markers[level][i];
//                markers[level][i] = new google.maps.Marker({
//                    title: details.level,
//                    position: new google.maps.LatLng(details.location[0], details.location[1]),
//                    clickable: false,
//                    draggable: true,
//                    flat: true
//                });
//            }
//        }
//    }